const { DataTypes } = require("Sequelize");
const sequelize = require("./index");

try {
  const UserModule = sequelize.define(
    "dzl_usermodule",
    {
      openid: {
        primaryKey: true,
        type: DataTypes.STRING(255),
        allowNull: false,
      },
      session_key: {
        type: DataTypes.STRING(255),
        allowNull: false,
      },
      name: {
        type: DataTypes.STRING(8),
        allowNull: true,
      },
      region: {
        type: DataTypes.STRING(32),
        allowNull: true,
      },
      phone: {
        type: DataTypes.STRING(32),
        allowNull: true,
        unique: true,
      },
      gender: {
        type: DataTypes.STRING(10),
        allowNull: true,
      },
    },

    {
      tableName: "users",
    }
  );
  const promise = UserModule.sync({ alter: true });
  promise.then(
    (success) => {
      console.log("UserModule模型同步成功", success);
    },
    (fail) => {
      console.log("UserModule模型同步失败", fail);
    }
  );

  module.exports = UserModule;
} catch (error) {
  console.log("数据表结构设计出错", error);
}
